package com.codeest.geeknews.base;

import android.content.Context;
import android.view.Gravity;

import com.alexvasilkov.gestures.Settings;

/**
 * Created by admin on 2017/8/18.
 */

public class GestureImageViewSetting {
    private static final float OVERSCROLL = 32f;
    private static final long SLOW_ANIMATIONS = 1500L;
    private Context context;
    private boolean isPanEnabled = true;
    private boolean isZoomEnabled = true;
    private boolean isRotationEnabled = false;
    private boolean isRestrictRotation = false;
    private boolean isOverscrollXEnabled = false;
    private boolean isOverscrollYEnabled = false;
    private boolean isOverzoomEnabled = true;
    private boolean isExitEnabled = true;
    private boolean isFillViewport = true;
    private Settings.Fit fitMethod = Settings.Fit.INSIDE;
    private int gravity = Gravity.CENTER;
    private boolean isSlow = false;

    private float overscrollX = isOverscrollXEnabled ? OVERSCROLL : 0f;
    private float overscrollY = isOverscrollYEnabled ? OVERSCROLL : 0f;
    private float overzoom = isOverzoomEnabled ? Settings.OVERZOOM_FACTOR : 1f;

    private GestureImageViewSetting() {

    }

    public long getDuration() {
        return isSlow ? SLOW_ANIMATIONS : Settings.ANIMATIONS_DURATION;
    }

    public static class Builder {
        GestureImageViewSetting setting;


        public Builder(Context context) {
            setting = new GestureImageViewSetting();
            setting.context = context;
        }

        public Builder setSetting(GestureImageViewSetting setting) {
            this.setting = setting;
            return this;
        }

        public Builder setPanEnabled(boolean panEnabled) {
            setting.isPanEnabled = panEnabled;
            return this;
        }

        public Builder setZoomEnabled(boolean zoomEnabled) {
            setting.isZoomEnabled = zoomEnabled;

            return this;
        }

        public Builder setRotationEnabled(boolean rotationEnabled) {
            setting.isRotationEnabled = rotationEnabled;
            return this;
        }

        public Builder setRestrictRotation(boolean restrictRotation) {
            setting.isRestrictRotation = restrictRotation;
            return this;
        }

        public Builder setOverscrollXEnabled(boolean overscrollXEnabled) {
            setting.isOverscrollXEnabled = overscrollXEnabled;
            setting.overscrollX = overscrollXEnabled ? OVERSCROLL : 0f;
            return this;
        }

        public Builder setOverscrollYEnabled(boolean overscrollYEnabled) {
            setting.isOverscrollYEnabled = overscrollYEnabled;
            setting.overscrollY = overscrollYEnabled ? OVERSCROLL : 0f;
            return this;
        }

        public Builder setOverzoomEnabled(boolean overzoomEnabled) {
            setting.isOverzoomEnabled = overzoomEnabled;
            setting.overzoom = overzoomEnabled ? Settings.OVERZOOM_FACTOR : 1f;
            return this;
        }

        public Builder setExitEnabled(boolean exitEnabled) {
            setting.isExitEnabled = exitEnabled;
            return this;
        }

        public Builder setFillViewport(boolean fillViewport) {
            setting.isFillViewport = fillViewport;
            return this;
        }

        public Builder setFitMethod(Settings.Fit fitMethod) {
            setting.fitMethod = fitMethod;
            return this;
        }

        public Builder setGravity(int gravity) {
            setting.gravity = gravity;
            return this;
        }

        public Builder setSlow(boolean slow) {
            setting.isSlow = slow;
            return this;
        }

        public GestureImageViewSetting creat() {
            return setting;
        }
    }

    public Context getContext() {
        return context;
    }

    public boolean isPanEnabled() {
        return isPanEnabled;
    }

    public boolean isZoomEnabled() {
        return isZoomEnabled;
    }

    public boolean isRotationEnabled() {
        return isRotationEnabled;
    }

    public boolean isRestrictRotation() {
        return isRestrictRotation;
    }

    public boolean isOverscrollXEnabled() {
        return isOverscrollXEnabled;
    }

    public boolean isOverscrollYEnabled() {
        return isOverscrollYEnabled;
    }

    public boolean isOverzoomEnabled() {
        return isOverzoomEnabled;
    }

    public boolean isExitEnabled() {
        return isExitEnabled;
    }

    public boolean isFillViewport() {
        return isFillViewport;
    }

    public Settings.Fit getFitMethod() {
        return fitMethod;
    }

    public int getGravity() {
        return gravity;
    }

    public boolean isSlow() {
        return isSlow;
    }

    public float getOverscrollX() {
        return overscrollX;
    }

    public float getOverscrollY() {
        return overscrollY;
    }

    public float getOverzoom() {
        return overzoom;
    }
}
